//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.aidong.dao.wills;

import com.aidong.dao.base.OrderSet;
import com.aidong.dao.wills.BaseDao;
import com.aidong.model.wills.GcBespeak;
import com.aidong.model.wills.PayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import org.springframework.stereotype.Repository;

@Repository
public class GcBespeakDao extends BaseDao<GcBespeak, Integer> {
	public GcBespeakDao() {
	}

	public boolean chkBespeakType1(int classId, String memberCode) {
		return this.getByWhere("classId=:p1 and memberType=1 and memberCode=:p2 and status>0", new Object[]{Integer.valueOf(classId), memberCode}) != null;
	}

	public boolean chkBespeakType2(int classId, String mobile) {
		return this.getByWhere("classId=:p1 and memberType=2 and mobile=:p2 and status>0", new Object[]{Integer.valueOf(classId), mobile}) != null;
	}

	public List<GcBespeak> getListByClass(int classId) {
		String sqlww = "classId=:p1 and status>0";
		return this.queryList(sqlww, new Object[]{Integer.valueOf(classId)}, (new OrderSet()).asc("bespeakDate"), -1);
	}

	public void addBespeak(GcBespeak bespeak) {
		this.add(bespeak);
		if(bespeak.getClassId() != null) {
			String sql = "update GcTimeTable set bespeakQuantity=bespeakQuantity+1, updateTime=getdate() where classId=:p1";
			this.updateBySql(sql, new Object[]{bespeak.getClassId()});
		}

	}

	public void updateCancel(GcBespeak bespeak) {
		String sql = "update GcBespeak set status=0, canceType=:p1, cancelUser=:p2, cancelTime=:p3 where autoId=:p4";
		this.updateBySql(sql, new Object[]{bespeak.getCanceType(), bespeak.getCancelUser(), bespeak.getClassTime(), bespeak.getAutoId()});
		if(bespeak.getClassId() != null) {
			sql = "update GcTimeTable set bespeakQuantity=bespeakQuantity-1, updateTime=getdate() where classId=:p1";
			this.updateBySql(sql, new Object[]{bespeak.getClassId()});
		}

	}

	public void updateClear(GcBespeak bespeak, List<PayList> payList) {
		String sql = "update GcBespeak set status=1, clearUser=:p1, clearTime=:p2 where autoId=:p3";
		this.updateBySql(sql, new Object[]{bespeak.getClearUser(), bespeak.getClearTime(), bespeak.getAutoId()});
		if(bespeak.getClassId() != null) {
			sql = "update GcTimeTable set clearQuantity=clearQuantity+1, updateTime=getdate() where classId=:p1";
			this.updateBySql(sql, new Object[]{bespeak.getClassId()});
		}

		Iterator i$ = payList.iterator();

		while(i$.hasNext()) {
			PayList pay = (PayList)i$.next();
			pay.setSaleId(bespeak.getAutoId());
			pay.setContractCode(String.valueOf(bespeak.getAutoId()));
			this.getSession().save(pay);
			if("S011".equalsIgnoreCase(pay.getPayType())) {
				sql = "update PayAli set status=:p1, payListId=:p2, salesCode=:p3, salesCode2=:p4, updateTime=:p5 where barCode=:p6";
				this.updateBySql(sql, new Object[]{Integer.valueOf(2), pay.getAutoId(), pay.getSalesCode(), pay.getSalesCode2(), new Date(), pay.getNote()});
			}
		}

	}
}
